# -*- coding: utf-8 -*-

from core.resources import CustomerModelResource
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
from apps.rms.models import PacketType, PacketField
from apps.pms.models import Product
from apps.rms.packet.widget import *


class PacketTypeResouces(CustomerModelResource):
    product = Field(attribute='product',
                    widget=ForeignKeyWidget(Product, field='name'))

    class Meta:
        model = PacketType
        fields = ('name', 'product', 'type', 'remark')
        import_id_fields = ('product', 'name')
        export_order = fields


class PacketFieldResouces(CustomerModelResource):
    product = Field(attribute='product',
                    widget=ForeignKeyWidget(Product, field='name'))
    packet = Field(attribute='packet',
                   widget=PacketTypeForeignKeyWidget(PacketType, field='name'))

    class Meta:
        model = PacketField
        fields = ('name', 'product', 'packet', 'sdx', 'type', 'length', 'desc', 'tshark', 'isjx',
                  'istl', 'issx', 'remark')
        import_id_fields = ('product', 'packet', 'name')
        export_order = fields
